<%@page contentType="text/html" pageEncoding="UTF-8"%>

<%@taglib prefix="f" uri="http://java.sun.com/jsf/core"%>
<%@taglib prefix="h" uri="http://java.sun.com/jsf/html"%>
<%@taglib prefix="rich" uri="http://richfaces.org/rich"%>
<%@taglib prefix="a4j" uri="http://richfaces.org/a4j"%>

<%@ page import="net.sf.jasperreports.engine.*" %>
<%@ page import="net.sf.jasperreports.engine.util.*" %>
<%@ page import="net.sf.jasperreports.engine.export.*" %>
<%@ page import="net.sf.jasperreports.j2ee.servlets.*" %>
<%@ page import="java.util.*" %>
<%@ page import="java.io.*" %>
<%@ page import="java.text.DateFormat" %>
<%@ page import="java.text.SimpleDateFormat" %>
<%@ page import="java.sql.DriverManager" %>
<%@ page import="java.sql.SQLException" %>
<%@ page import="net.sf.jasperreports.view.JasperViewer" %>



<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">
  
<f:view>

    <%@include file="../WEB-INF/jspf/cabecera.jspf" %>

    <html>
        <head>
            <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
            <title>Cuentas por Cobrar</title>
             <link rel=stylesheet type="text/css" href="/cxc/style.css">
         </head>
        <body>
            <table>
                <tr>
                    <td width="35">

                    </td>
                    <td>

              <h:form id="frmlista">

                    <%
        DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");

        ServletContext context = this.getServletConfig().getServletContext();

        String reportSource =application.getRealPath("/RegPago/CtasPendientes.jrxml")  ;


        Map<String, Object> params = new HashMap<String, Object>();
    params.put("CxC", "Carlos CedeFer");
        try {
            params.put("fdesde", dateFormat.parse("16/07/2010"));
            params.put("fhasta", dateFormat.parse("15/12/2010"));
        } catch (Exception e) {
            e.printStackTrace();
            out.println(e.toString());
        }
        try {

            JasperReport jasperReport = JasperCompileManager.compileReport(reportSource);
            //JasperCompileManager.compileReportToFile(reportSource);
            // Make the driver class available.
            Class.forName("com.sun.sql.jdbc.sqlserver.SQLServerDriver");

            // Create a connection to pass into the report.
            java.sql.Connection conn = DriverManager.getConnection(
                    "jdbc:sun:sqlserver://localhost:1433;databaseName=SIGEADMI;user=sa;password=adminadmin");

            JasperPrint jasperPrint =
                    JasperFillManager.fillReport(
                    jasperReport,
                    params,
                    conn);

           JasperViewer.viewReport(jasperPrint,false);


            JRHtmlExporter exporter = new JRHtmlExporter();
            StringBuffer sbuffer = new StringBuffer();

            exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
            exporter.setParameter(JRExporterParameter.OUTPUT_WRITER, out);
            exporter.setParameter(JRHtmlExporterParameter.IMAGES_URI, "http://localhost:8080/cxc/images/");

            exporter.exportReport();
 
       //     out.println("REPORTE GENERADO EXITOSAMENTE");

        } catch (JRException e) {
          //  e.printStackTrace();
          //  out.println(e.toString());

        } // Exception handling for the Class.forName method.
        catch (ClassNotFoundException ex) {
            ex.printStackTrace();
            out.println(ex.toString());

        } // Exception handling for the DriverManager.getConnection method.
        catch (SQLException ex) {
            ex.printStackTrace();
            out.println(ex.toString());

        }

%>

            </h:form>

                    </td>
                    <td>

                    </td>

                </tr>
            </table>
                     <div class="centrar">
            <a href=" "><img src="/cxc/img/logo_ta_resize.png" border="0"/></a>
        </div>

    <%@include file="../WEB-INF/jspf/pie.jspf" %>

        </body>
    </html>
</f:view>
